#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 1e3 + 10;
const int MAXM = 1e4 + 10;
int n, m;
struct NODE {
    int x, y;
    int t;
    NODE() { x = y = t = 0; }
    NODE(int x, int y, int t) {
        this->x = x;
        this->y = y;
        this->t = t;
    }
};
NODE data[MAXM];
int f[MAXM];
int ans = 1;

int main() {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> data[i].t >> data[i].x >> data[i].y;
        f[i] = 1;
    }
    for (int j = 1; j <= m; j++) {
        for (int i = 1; i <= j - 1; i++) {
            int dis = abs(data[i].x - data[j].x) + abs(data[i].y - data[j].y);
            if (dis <= data[j].t - data[i].t) {
                f[j] = max(f[j], f[i] + 1);
                ans = max(ans, f[j]);
            }
        }
    }
    cout << ans;
}